<?php

class allocationsmodel extends CI_Model
{

    public function __construct()
    {
        $this->load->database();
    }

    public function view()
    {
        $query = $this->db->get('allocations');
        return $query->result_array();
    }

    public function addallocation()
    {
        $this->load->helper('url');
        $data = array(
            'id' => $this->input->post('id'),
            'serial_id' => $this->input->post('serial_id'),
            'employee_id'=>$this->input->post('employee_id'),
            'allocation_date'=>$this->input->post('allocation_date'),
            'allocation_status'=>$this->input->post('allocation_status'),
            'region'=>$this->input->post('region'),
            'location'=>$this->input->post('location'),
        );
        return $this->db->insert('allocations', $data);
    }

    public function getData()
    {
        $this->load->helper('url');
        $id = $this->input->post('serial_id');
        $query = $this->db->get_where('allocations',array('serial_id' => $id));
        return $query->row_array();

    }
    public function updateData()
    {
        $this->load->helper('url');
        $data = array(
            'id' => $this->input->post('device_id'),
            'serial_id' => $this->input->post('serial_id'),
            'employee_id'=>$this->input->post('employee_id'),
            'allocation_date'=>$this->input->post('allocation_date'),
            'allocation_status'=>$this->input->post('allocation_status'),
            'region'=>$this->input->post('region'),
            'location'=>$this->input->post('location'),
        );
        $this->db->where('serial_id',$data['serial_id']);
        return $this->db->update('allocations', $data);
    }
}